﻿// <copyright file="Environment.cs" company="Microsoft Corporation">
// Copyright (c) 2009 Microsoft Corporation All Rights Reserved
// </copyright>
// <author>Michael S. Scherotter</author>
// <email>mischero@microsoft.com</email>
// <date>2008-09-23</date>
// <summary>The Silverlight Application</summary>

// Ignore SA1300
namespace opensocial
{
    using System.Windows.Browser;

    /// <summary>
    /// OpenSocial Environment
    /// </summary>
    public class Environment
    {
        /// <summary>
        /// JavaScript environment object
        /// </summary>
        private ScriptObject environment;

        /// <summary>
        /// Initializes a new instance of the Environment class.
        /// </summary>
        /// <param name="environment">environment object</param>
        internal Environment(ScriptObject environment)
        {
            this.environment = environment;
        }

        /// <summary>
        /// Get the domain
        /// </summary>
        /// <returns>the domain</returns>
        [System.Diagnostics.CodeAnalysis.SuppressMessage("Microsoft.Design", "CA1024:UsePropertiesWhereAppropriate", Justification = "Mirroring OpenSocial API."), System.Diagnostics.CodeAnalysis.SuppressMessage("Microsoft.Naming", "CA1709:IdentifiersShouldBeCasedCorrectly", MessageId = "get", Justification = "Mirroring OpenSocial API.")]
        public string getDomain()
        {
            return this.environment.Invoke("getDomain") as string;
        }

        /// <summary>
        /// Get the surfaces
        /// </summary>
        /// <returns>the OpenSocial Surface</returns>
        [System.Diagnostics.CodeAnalysis.SuppressMessage("Microsoft.Design", "CA1024:UsePropertiesWhereAppropriate", Justification = "Mirroring OpenSocial API."), System.Diagnostics.CodeAnalysis.SuppressMessage("Microsoft.Naming", "CA1709:IdentifiersShouldBeCasedCorrectly", MessageId = "get", Justification = "Mirroring OpenSocial API.")]
        public Surface getSurface()
        {
            Surface surface = new Surface(this.environment.Invoke("getSurface") as ScriptObject);

            return surface;
        }

        /// <summary>
        /// Returns an array of all the supported surfaces.
        /// </summary>
        /// <returns>an array of all the supported surfaces</returns>
        [System.Diagnostics.CodeAnalysis.SuppressMessage("Microsoft.Design", "CA1024:UsePropertiesWhereAppropriate", Justification = "Mirroring OpenSocial API."), System.Diagnostics.CodeAnalysis.SuppressMessage("Microsoft.Naming", "CA1709:IdentifiersShouldBeCasedCorrectly", MessageId = "get", Justification = "Mirroring OpenSocial API.")]
        public ScriptObject getSupportedSurfaces()
        {
            return this.environment.Invoke("getSupportedSurfaces") as ScriptObject;
        }

        /// <summary>
        /// get the parameters
        /// </summary>
        /// <returns>the parameters</returns>
        [System.Diagnostics.CodeAnalysis.SuppressMessage("Microsoft.Design", "CA1024:UsePropertiesWhereAppropriate", Justification = "Mirroring OpenSocial API."), System.Diagnostics.CodeAnalysis.SuppressMessage("Microsoft.Naming", "CA1704:IdentifiersShouldBeSpelledCorrectly", MessageId = "Params", Justification = "Mirroring OpenSocial API."), System.Diagnostics.CodeAnalysis.SuppressMessage("Microsoft.Naming", "CA1709:IdentifiersShouldBeCasedCorrectly", MessageId = "get", Justification = "Mirroring OpenSocial API.")]
        public Map<string, string> getParams()
        {
            ScriptObject parameters = this.environment.Invoke("getParams") as ScriptObject;

            var result = new Map<string, string>(parameters);

            return result;
        }

        /// <summary>
        /// returns if the environment has a capability
        /// </summary>
        /// <param name="functionName">the function name</param>
        /// <returns>true if the environment has a capability</returns>
        [System.Diagnostics.CodeAnalysis.SuppressMessage("Microsoft.Naming", "CA1709:IdentifiersShouldBeCasedCorrectly", MessageId = "has", Justification = "Mirroring OpenSocial API.")]
        public bool hasCapability(string functionName)
        {
            return (bool) this.environment.Invoke("hasCapability", functionName);
        }

        /// <summary>
        /// returns whether the environment supports a field
        /// </summary>
        /// <param name="objectType">the objectType</param>
        /// <param name="fieldName">the field name</param>
        /// <returns>the environment supports a field</returns>
        [System.Diagnostics.CodeAnalysis.SuppressMessage("Microsoft.Naming", "CA1709:IdentifiersShouldBeCasedCorrectly", MessageId = "supports", Justification = "Mirroring OpenSocial API.")]
        public bool supportsField(string objectType, string fieldName)
        {
            return (bool) this.environment.Invoke("supportsField", objectType.ToString(), fieldName);
        }
    }
}
